<template>
	<div>
		<!-- 出库材料信息 -->
		<div style="width: 100%;height: 15vh;background-color: #4142F4">
			<div style="color: #FFFFFF;font-weight: 700;font-size: 38rpx;margin-left: 10%;padding-top: 6%">
				出库
			</div>
		</div>
		<!-- 出库详细信息 -->
		<div id="warehouse_div1">
			<!-- 处置时间 -->
			<div>
				<van-field v-model="handle_time" label="处置时间" placeholder="请输入处置时间" @input="handle_time_input" />
			</div>
			<!-- 处置金额 -->
			<div>
				<van-field v-model="handle_money" label="处置金额" placeholder="请输入处置金额" @input="handle_money_input" />
			</div>
			<!-- 处置数量 -->
			<div>
				<van-field v-model="handle_num" label="处置数量" placeholder="请输入处置数量" @input="handle_num_input" />
			</div>
			<!-- 备注 -->
			<div>
				<van-field v-model="handle_remarks" label="备注" placeholder="请输入备注" @input="handle_remarks_input" />
			</div>
			<!-- 提交 -->
			<div style="padding-bottom: 5%;padding-top: 5%;">
				<van-button color="#4142F4" type="primary" block @click="handle_old()">处置</van-button>
			</div>
		</div>
		
	</div>
</template>

<script>
	import { BaseUrl } from '@/util/util.js';
	const PrefixUrl = BaseUrl();
	export default {
		data(){
			return{
				handle_time: '',
				handle_money: '',
				handle_num: '',
				handle_remarks: '',
				show: false,
				actions: [],
				ware_id: '',
				stock_num: ''
			}
		},
		onLoad: function(option) {
			this.ware_id = option.id
			this.stock_num = option.stocknum
			this.handle_time = this.format(new Date)
		},
		created() {
			
		},
		methods:{
			handle_time_input(event){
				this.handle_time = event.detail
			},
			handle_money_input(event){
				this.handle_money = event.detail
			},
			handle_num_input(event){
				this.handle_num = event.detail
			},
			handle_remarks_input(event){
				this.handle_remarks = event.detail
			},
			//格式化时间
			format(dat) {
				//获取年月日，时间
				var year = dat.getFullYear();
				var mon = (dat.getMonth() + 1) < 10 ? "0" + (dat.getMonth() + 1) : dat.getMonth() + 1;
				var data = dat.getDate() < 10 ? "0" + (dat.getDate()) : dat.getDate();
				var hour = dat.getHours() < 10 ? "0" + (dat.getHours()) : dat.getHours();
				var min = dat.getMinutes() < 10 ? "0" + (dat.getMinutes()) : dat.getMinutes();
				var seon = dat.getSeconds() < 10 ? "0" + (dat.getSeconds()) : dat.getSeconds();
				var newDate = year + mon + data
				return newDate;
			},
			// 处置
			handle_old(){
				console.log(this.stock_num)
				console.log(this.handle_num)
				if(this.handle_money === '' || this.handle_num === ''){
					uni.showToast({
						title: '未填写完整，请检查!',
						mask: true,
						icon: 'none'
					})
				} else if(this.handle_num * 1 > this.stock_num * 1){
					uni.showToast({
						title: '处置数量大于库存数量，请检查!',
						mask: true,
						icon: 'none'
					})
				}else{
					uni.request({
						method: 'POST',
						url: PrefixUrl + '/equimentHandle/saveHandle',
						data: {
							bdst: uni.getStorageSync('userbdst'),
							ware_id: this.ware_id,
							handle_num: this.handle_num,
							handle_time: this.handle_time,
							handle_money: this.handle_money,
							remarks: this.handle_remarks
								
						},
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'token': uni.getStorageSync('token')
						},
						success: (res) => {
							if(res.data.obj){
								uni.navigateBack({
									delta: 1
								});
								uni.showToast({
									title: '处置成功!',
									mask: true,
									icon: 'none'
								})
							}else {
								uni.showToast({
									title: '处置失败，请联系科信部!',
									mask: true,
									icon: 'none'
								})
							}
						}
					})
				}
				
			}
		}
	} 
</script>

<style>
	#warehouse_div1 {
		position: absolute;
		top: 8vh;
		width: 92%;
		height: 100vh;
		background-color: #FFFFFF;
		left: 4%;
		border-radius: 20rpx;
		padding-top: 5%;
	}
	
	.warehouse_div1_font {
		margin-left: 5%;
		font-size: 30rpx;
		margin-bottom: 5%;
	}
	
	.opinion_div3 {
		margin-left: 24%;
		width: 100%;
		display: flex;
	}
	
	.opinion_div1 {
		margin-left: 4.5%;
		width: 100%;
		display: flex;
	}
</style>